---
title: Badge
description: A badge or a component that looks like a badge.

links:
  doc: https://base-ui.com/react/components/badge#api-reference
---

<ComponentPreview name="p-badge-1" />

## Installation

<CodeTabs>

<TabsList>
  <TabsTab value="cli">CLI</TabsTab>
  <TabsTab value="manual">Manual</TabsTab>
</TabsList>
<TabsPanel value="cli">

```bash
npx shadcn@latest add @coss/badge
```

</TabsPanel>

<TabsPanel value="manual">

<Steps>

<Step>Install the following dependencies:</Step>

```bash
npm install @base-ui-components/react
```

<Step>Import the following variables into your CSS file</Step>

```css
@theme inline {
  --color-destructive-foreground: var(--destructive-foreground);
  --color-info: var(--info);
  --color-info-foreground: var(--info-foreground);
  --color-success: var(--success);
  --color-success-foreground: var(--success-foreground);
  --color-warning: var(--warning);
  --color-warning-foreground: var(--warning-foreground);
}

:root {
  --destructive-foreground: var(--color-red-700);
  --info: var(--color-blue-500);
  --info-foreground: var(--color-blue-700);
  --success: var(--color-emerald-500);
  --success-foreground: var(--color-emerald-700);
  --warning: var(--color-amber-500);
  --warning-foreground: var(--color-amber-700);
}

.dark {
  --destructive-foreground: var(--color-red-400);
  --info: var(--color-blue-500);
  --info-foreground: var(--color-blue-400);
  --success: var(--color-emerald-500);
  --success-foreground: var(--color-emerald-400);
  --warning: var(--color-amber-500);
  --warning-foreground: var(--color-amber-400);
}
```

<Step>Copy and paste the following code into your project.</Step>

<ComponentSource name="badge" title="components/ui/badge.tsx" />

<Step>Update the import paths to match your project setup.</Step>

</Steps>

</TabsPanel>

</CodeTabs>

## Usage

```tsx
import { Badge } from "@/components/ui/badge"
```

```tsx
<Badge>Badge</Badge>
```

## Link

You can use the [`render`](https://base-ui.com/react/utils/use-render#migrating-from-radix-ui) prop to make another component look like a badge. Here's an example of a link that looks like a badge.

```tsx
import Link from "next/link"

import { Badge } from "@/components/ui/badge"

export function LinkAsBadge() {
  return <Badge render={<Link href="/pricing" />}>New</Badge>
}
```

## Examples

### Outline

<ComponentPreview name="p-badge-2" />

### Secondary

<ComponentPreview name="p-badge-3" />

### Destructive

<ComponentPreview name="p-badge-4" />

### Info

<ComponentPreview name="p-badge-5" />

### Success

<ComponentPreview name="p-badge-6" />

### Warning

<ComponentPreview name="p-badge-7" />

### Error

<ComponentPreview name="p-badge-8" />

### Small

<ComponentPreview name="p-badge-9" />

### Large

<ComponentPreview name="p-badge-10" />

### With Icon

<ComponentPreview name="p-badge-11" />

### With Link

<ComponentPreview name="p-badge-12" />

### With Count

<ComponentPreview name="p-badge-13" />

## Comparing with Radix / shadcn

If you’re already familiar with Radix UI and shadcn/ui, this guide highlights the small differences and similarities so you can get started with **coss ui** quickly.

### Prop Mapping

| Component | Radix UI Prop | Base UI Prop |
| --------- | ------------- | ------------ |
| `Badge`   | `asChild`     | `render`     |

### Quick Checklist

- Replace `asChild` → `render` on `Badge`

### Additional Notes

**Size Comparison**

Compared to shadcn/ui, our `Badge` component includes size variants for better density control. shadcn/ui badges have a fixed size, while our component offers flexible sizing with `sm`, `default`, and `lg` options.

So, if you want to preserve the original shadcn/ui badge size, you should use the `lg` size in coss ui.

**New Variants**

We've added new colored variants to the existing ones (`default`, `destructive`, `outline`, `secondary`) for better semantic meaning and visual communication:

We've added new colored variants for better semantic meaning:

| Variant   | Description                    |
| --------- | ------------------------------ |
| `info`    | Blue badge for information     |
| `success` | Green badge for success states |
| `warning` | Yellow badge for warnings      |
| `error`   | Red badge for errors           |

Ensure you have the following variables imported in your CSS file:

- `--destructive-foreground`
- `--info`
- `--info-foreground`
- `--success`
- `--success-foreground`
- `--warning`
- `--warning-foreground`

### Comparison Example

<span data-lib="radix-ui">
```tsx title="shadcn/ui"
// [!code word:asChild]
import Link from "next/link"
import { Badge } from "@/components/ui/badge"

export function LinkAsButton() {
  return (
    <Badge asChild>
      <Link href="/login">Login</Link>
    </Badge>
  )
}
```
</span>

<span data-lib="base-ui">
```tsx title="coss ui"
// [!code word:render]
import Link from "next/link"
import { Badge } from "@/components/ui/badge"

export function LinkAsButton() {
  return (
    <Badge render={<Link href="/login" />}>Login</Badge>
  )
}
```
</span>
